<!--
 * @Descripttion:
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-11-19 18:05:02
-->
<template>
  <div class="lb-dis-set">
    <top-nav></top-nav>
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="setForm"
        :rules="setFormRules"
        ref="setForm"
        label-width="150px"
        class="set-form"
      >
        <el-form-item label="最低提现金额 (¥)" prop="cash_mini">
          <el-input-number
            class="lb-input-number"
            v-model="setForm.cash_mini"
            :controls="false"
            :precision="2"
            :min="0.1"
            :max="10000"
          ></el-input-number>
          <lb-tool-tips
            >钱包余额，最低提现额度。达到此金额后才可以申请提现</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="管理员微信号" prop="admin_account">
          <el-input
            placeholder="请输入微信账号"
            v-model="setForm.admin_account"
          ></el-input>
          <lb-tool-tips>管理员微信账号，用于申请提现</lb-tool-tips>
        </el-form-item>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo('setForm')">{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  reg
} from '@/utils/reg'
export default {
  data () {
    return {
      tips_staff: {
        1: `用户消费, 其对应员工所得提成。当消费的用户的上线与消费所属${this.$t('menu.BusinessCard')}为同一个人时, 只计算员工提成, 如果没有设置员工提成则计算分销提成, 都没有设置则不计算。提成为百分比，取值0%到100%`,
        2: `用户消费, 其对应员工所得提成。当消费的用户的上线与消费所属${this.$t('menu.BusinessCard')}为同一个人时, 只计算员工提成, 如果没有设置员工提成则计算分销提成, 都没有设置则不计算。提成为固定金额，最多保留两位小数，若填写的金额大于所购买规格的商品，也是按照填写的金额来进行提成，请谨慎填写此金额`
      },
      setForm: {
        selling_style: 0,
        first_extract: 0,
        staff_extract: 0,
        first_extract_cash: 0,
        staff_extract_cash: 0,
        cash_mini: 0,
        admin_account: ''
      },
      setFormRules: {
        cash_mini: { required: true, validator: reg.isMoney, trigger: 'blur' },
        admin_account: { required: true, type: 'string', message: '请输入微信账号', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    getFormInfo () {
      this.$api.getEditDistributionSetting().then(res => {
        console.log(res)
        if (res.code === 200) {
          this.setForm = res.data
          console.log(res.data)
        }
      })
    },
    submitFormInfo (name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          let { setForm } = this
          let attr = ['first_extract', 'staff_extract', 'first_extract_cash', 'staff_extract_cash']
          attr.map((item) => {
            setForm[item] = setForm[item] || 0
          })
          this.$api.getEditDistributionSetting(setForm).then(res => {
            console.log(res)
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-dis-set {
  width: 100%;
  .set-form {
    .el-input {
      width: 300px;
    }
    .lb-input-number {
      width: 300px;
    }
  }
}
</style>
